package cn.hamster3.mc.plugin.core.bukkit.command.core.sub;

import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;

public class MemoryCommand extends ChildCommand {
    public static final MemoryCommand INSTANCE = new MemoryCommand();

    private MemoryCommand() {
    }

    @Override
    public @NotNull String getName() {
        return "memory";
    }

    @Override
    public @NotNull String getUsage() {
        return "memory";
    }

    @Override
    public boolean hasPermission(@NotNull CommandSender sender) {
        return true;
    }

    @Override
    public @NotNull String getDescription() {
        return "查看内存信息";
    }

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
        Runtime runtime = Runtime.getRuntime();
        sender.sendMessage(String.format("活跃内存：%.2f MB", (runtime.totalMemory() - runtime.freeMemory()) / 1024.0 / 1024.0));
        sender.sendMessage(String.format("空闲内存：%.2f MB", runtime.freeMemory() / 1024.0 / 1024.0));
        sender.sendMessage(String.format("占用系统内存：%.2f MB", runtime.totalMemory() / 1024.0 / 1024.0));
        sender.sendMessage(String.format("最大可用内存：%.2f MB", runtime.maxMemory() / 1024.0 / 1024.0));
        return true;
    }

    @Override
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
        return Collections.emptyList();
    }
}
